﻿//产品收货 确认
var columns =
            [
                 { display: 'Key', name: 'Id', type: 'text', hide: 1 },
                { display: '发货单号', name: 'DeliveryNo', mintWidth: 80, width: 120 }, //, type: 'int', mintWidth: 40, width: 100
                {display: '发货人时间', name: 'DeliveryDate', mintWidth: 180, width: 180, type: 'selfDate' },
                {display: '仓库名称', name: 'StorehouseName', mintWidth: 80, width: 140 },
                 { display: '发货人名称', name: 'DeliveryorName', mintWidth: 80, width: 120 },
                  { display: '送货人名称', name: 'SenderName', mintWidth: 80, width: 120 },
                   { display: '收货单位名称', name: 'DeliveryName', mintWidth: 80, width: 120 },
                { display: '确认人', name: 'AffirmorName', mintWidth: 80, width: 120 },
                { display: '确认时间', name: 'AffirmDate', mintWidth: 180, width: 180, type: 'selfDate' },
                 { display: '确认状态', name: 'AffirmStateName', mintWidth: 100, width: 140 },
                 //{ display: '是否结算', name: 'SettleState', mintWidth: 100, width: 140 },
               // { display: '删除状态', name: 'DeleteState', mintWidth: 80, width: 140 },
                 { display: '备注', name: 'Remarks', mintWidth: 80, width: 120 }
             ];

var manager;
//init controls
$(document).ready(function () {
    initligerGrid();
});

function initligerGrid() {
    manager = null;
    manager = $("#ProductDeliveryGrid").ligerGrid({
        columns: columns,
        title: '产品发货管理',
        showTitle: true,
        width: '100%',
        enabledSort: true,
        height: '99%',
        checkbox: false,
        rownumbers: true,
        toolbar: { items: [{ text: '收货确认', click: audioOperation, icon: 'modify' },
                                    { line: true },
                                    { text: '查看', click: dialogDetailView, img: '../Content/images/Search.png'}]
        },
        url: "../ProductDelivery/GetJsonOfDatas?isConfirm=false&rand=" + Math.random(),
        onDblClickRow: function (data, rowindex, rowobj) { dialogView(data.Id); }
    });
}


//detail
function dialogDetailView() {
    var row = manager.getSelectedRow();
    if (!row) { $.ligerDialog.success('请选择要查看的行!'); return; }
    var billId = row["Id"].toString();
    dialogView(billId);
 }
function dialogView(billId) {
    $.ligerDialog.open({ url: "../ProductAllot/Detail?id=" + billId, height: getDialogHeight(), width: getDialogWidth(), isResize: true, isHidden: false });
}
//确认 
function audioOperation() {
    var row = manager.getSelectedRow();
    if (!row) {
        $.ligerDialog.success('请选择要编辑的行!'); return;
    }
    $.ligerDialog.confirm('确定要收货确认吗？', function (yes) {
        if (yes) {
            $.get("../ProductDelivery/Audit?billId=" + row.Id + "&rand=" + Math.random(), {}, function (data) {
                if (data != undefined && data == "9") {
                    $.ligerDialog.success('收货确认成功!');
                    initligerGrid();
                }
            });
        }
    });
}
